﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using UtilityLibrary;
using Microsoft.Xna.Framework.Graphics;

namespace GUILibrary
{
    public class TextBox : Component
    {
        /// <summary>
        /// The text to display to the screen
        /// </summary>
        public string TextToDisplay
        {
            get;
            set;
        }

        /// <summary>
        /// The asset for the backdrop of the text area
        /// </summary>
        public string BackdropAsset
        {
            get;
            set;
        }

        /// <summary>
        /// Where to begin drawing the text.
        /// </summary>
        public Vector2 TextOffset
        {
            get;
            set;
        }

        /// <summary>
        /// The maximum length of any line in this textbox.
        /// </summary>
        public float LineWidth
        {
            get;
            set;
        }

        /// <summary>
        /// The color to display the text in.
        /// </summary>
        public Color TextColor
        {
            get;
            set;
        }

        private Texture2D backdropTexture;

        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch batch)
        {
            batch.Draw(backdropTexture, ScreenPosition, Color.White);

            PrimitiveBrush.RenderTextWrap(batch,
                TextToDisplay,
                ScreenPosition + TextOffset,
                LineWidth,
                TextColor);
        }

        public override void Load(Microsoft.Xna.Framework.Content.ContentManager cm)
        {
            backdropTexture = cm.Load<Texture2D>(BackdropAsset);
            TextColor = new Color(TextColor.R, TextColor.G, TextColor.B, 255);
        }
    }
}
